// jQuery Alert Dialogs Plugin
//
// Version 1.1
//
// Cory S.N. LaViska
// A Beautiful Site (http://abeautifulsite.net/)
// 14 May 2009
//
// Visit http://abeautifulsite.net/notebook/87 for more information
//
// Usage:
//		displayMessage( message, [ ] )
// 
// History:
//
//		1.00 - Released (29 December 2008)
//
//		1.01 - Fixed bug where unbinding would destroy all resize events
//
// License:
// 
// This plugin is dual-licensed under the GNU General Public License and the MIT License and
// is copyright 2008 A Beautiful Site, LLC. 
//
(function($) {
	
	$.dM = {		
		// These properties can be read/written by accessing $.dM.propertyName from your scripts at any time
		
		verticalOffset: -75,                // vertical offset of the dialog from center screen, in pixels
		horizontalOffset: 0,                // horizontal offset of the dialog from center screen, in pixels/
		repositionOnResize: true,           // re-centers the dialog on window resize
		overlayOpacity: .01,                // transparency level of overlay
		overlayColor: '#FFF',               // base color of overlay
		draggable: true,                    // make the dialogs draggable (requires UI Draggables plugin)
		okButton: '&nbsp;OK&nbsp;',         // text for the OK button
		cancelButton: '&nbsp;Cancel&nbsp;', // text for the Cancel button
		dialogClass: null,                  // if specified, this class will be applied to all dialogs
		alert: function(message,typeCss,messageId) {
			if( typeCss == null ) typeCss = '0';
			
			$.dM._show( message,typeCss,messageId);
		},
		// Private methods
		
		_show: function(msg,typeCss,messageId) {
			switch( typeCss ) {
				case '0':
					typeCss='alert';
				break;
				case '1'://成功
					typeCss='successInline';
				break;
				case '2'://失败
					typeCss='errorInline';
				break;
			}
			$(messageId).empty();
			$(messageId).append(
			    '<div id="popup_content_inline" ><p>' +
			      '<div id="popup_message_inline"></div>' +				
			  '</p></div>');
			// IE6 Fix
			//var pos = ($.browser.msie && parseInt($.browser.version) <= 6 ) ? 'absolute' : 'fixed'; 			
				
			$("#popup_content_inline").addClass(typeCss);
			$("#popup_message_inline").text(msg);
			$("#popup_message_inline").html( $("#popup_message_inline").text().replace(/\n/g, '<br />') );			
			
		}
		
	}
	// Shortuct functions
	displayMessage = function(message,typeClass,messageId) {
		if( messageId == null ) messageId = '#dynamicMessage';
		$("div[id^='dynamicMessage']").empty();
		$.dM.alert(message,typeClass,messageId);
		var anchorName= "#anchor"+messageId.substring(1,messageId.length );
		if(jQuery.isEmptyObject($(anchorName))){
			if ($(anchorName)[0].click){
			$(anchorName)[0].click();
			}else{ 
				window.location = $(anchorName).attr('href');
			}
		}
		
		
	};	
})(jQuery);